import re

# re_01 = re.match(r'u', 'liuyuan').group()

# re_01 = re.search(r'u', 'liuyuan1').group()

# print(re_01)

def test_01():
    re_01 = re.search(r'[a-z]+','liuyaN1234ab9').group()
    re_02 = re.search(r'[a-z]+', 'liuyaN1234ab9', re.I).group()
    print(re_01)
    print(re_02)

# 匹配是否以数字开头
def test_02():
    if re.match(r'[0-9]', 'df2ad'):
        print('success')
    else:
        print('fail')

# 匹配以字母开头
def test_03():
    if re.match(r'[a-z]', 'Aer32r'):
        print("以小写字母开头")
    else:
        print("不是以小写字母开头")

# 用空格分隔
def test_04():
    re_01 = re.split(r'\s+', 'ab    c')
    print(re_01)


# 用逗号分隔
def test_05():
    re_01 = re.split(r'[\s\,]+', 'a,b, c,   c d')
    print(re_01)

def test_06():
    print(re.match('www', 'www.runoob.com').span())
    print(re.match('com', 'www.runoob.com'))


def test_07():
    line = 'Cats are smarter than dogs'
    matchObj = re.match(r'(.*) are (.*?) .*')

# 拆分字符串
def test_08():
    str_01 = 'wadadfaera'
    pattern = re.compile('a')
    ret = pattern.split(str_01)
    print(ret)

# 匹配中文 在Python中匹配中文是有范围的
def test_09():
    str_01 = "saddad我爱我的祖国adawdfew"
    pattern = re.compile('[\u4e00-\u9fa5]+') # 至少出现一次
    ret_01 = pattern.findall(str_01)
    ret_02 = pattern.match(str_01)
    print(ret_01)
    print(ret_02)



test_09()